package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle.paymentDetails;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.module.export.DictDataVo;
import com.yycx.common.base.module.export.ExportField;
import com.yycx.common.mybatis.interceptor.ExportInterceptor;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.bus.client.entity.hy.BusPaymentDetails;
import com.yycx.module.bus.client.entity.BusSaleman;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 业务员资金支付付款账户明细
 *
 * @author zyf
 */
@Component
public class HyPaymentDetailsPageListHandler implements PageInterceptor<BusPaymentDetails>, ExportInterceptor {


    @Override
    public void prepare(CriteriaQuery<BusPaymentDetails> cq, PageParams pageParams, EntityMap params) {
        //结算单ID
        String paymentId = params.get("paymentId");
        String saleManId = params.get("saleManId");
        cq.select(BusPaymentDetails.class, "*");
        cq.addSelect(BusSaleman.class, "saleManName");
        cq.eq(true, "bpd.paymentId", paymentId);
        cq.eq(true, "bpd.saleManId", saleManId);
        cq.createJoin(BusSaleman.class);
        cq.orderByDesc("bpd.createTime");
    }

    @Override
    public void initExcelExportEntity(ExportField exportField, List list) {
        Object key = exportField.getKey();
        if (key.equals("invoiceType")) {
            List<DictDataVo> dictDataVos = new ArrayList<>();
            DictDataVo dictDataVo = new DictDataVo();
            dictDataVo.setLabel("专票");
            dictDataVo.setValue(2);
            DictDataVo dictDataVo2 = new DictDataVo();
            dictDataVo2.setLabel("普票");
            dictDataVo2.setValue(1);
            dictDataVos.add(dictDataVo);
            dictDataVos.add(dictDataVo2);
            exportField.setDictData(dictDataVos);
            exportField.setReplace();
        }
    }
}
